package com 
{
	import com.services.WebService;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.utils.ByteArray;
	import flash.utils.getTimer;
	/**
	 * ...
	 * @author db0@qq.com
	 */
	public class Wsdata extends Sprite
	{
		/**
		 * http://ws.huaien.com/FlashAction.asmx?WSDL/GetjwList
		 */
		//private var initTime:Number;
		public static var ws:WebService = new WebService();
		public static var ListAction:String;
		public static var ListElement:String;
		public static var UserName:String=" ";
		public static var UserCode:uint;
		
		public static var main:Wsdata;
		public static var bytes:ByteArray;
		public static var type:int;
		
		public function Wsdata() 
		{
			main = this;
			ws.addEventListener(Event.CONNECT, connected);
			//ws.connect("http://ws.cdyne.com/ip2geo/ip2geo.asmx?WSDL");
			//ws.connect("http://ws.huaien.com/FlashAction.asmx?WSDL");
			ws.connect("http://ws.huaien.com/uploadhead.asmx?WSDL");
			ws.cacheResults = true;
		}
		
		
		private function connected(evt:Event):void {
			bytes = new ByteArray();
			bytes.writeObject("11111111111");
			type=1;
			ws.UploadHead(UploadHead,bytes,type);
			//ws.GetUserCode(GetUserCode);
			//获取用户id//http://ws.huaien.com/FlashAction.asmx/GetUserCode
			//ws.GetUserName(GetUserName);//获取用户名//http://ws.huaien.com/FlashAction.asmx/GetUserName
			/**
			 * 获取留言
			 * int(DataModel.getInstance().kid),馆id//KeyID
			 * int(DataModel.getInstance().tid)//TypeID
			 * http://ws.huaien.com/FlashAction.asmx/GetListMessage?KeyID=1000368&TypeID=1
			 * 
			 */
			//ws.GetListMessage(GetListMessage,1000368,1);//获取留言
			/**
			 * 留言
			 * http://ws.huaien.com/FlashAction.asmx/AddFlashMessage?KeyID=1000368&Content=%22great%20jobs%22&TypeID=1&Status=1&Remark=%22%22&CreateDate=2012-12-25T13:30:22.353&CreateUserCodeID=10007&CreateUserName=%22%22
			 * message.Keyid,message.Content,message.TypeID,message.Status,message.Remark,message.CreateDate,message.CreateUserCodeID,message.CreateUserName
			 */
			//ws.AddFlashMessage(AddFlashMessage, 1000368/*message.Keyid馆id*/,"乔总，你太伟大了",1,/*message.Status*/1,/*message.Remark*/"","2012-12-25T11:32:31.513"/*message.CreateDate*/,10007/*message.CreateUserCodeID*/,"雨阳"/*message.CreateUserName*/);//获取??
			
			
			/**
			 * 获取主菜单
			 * http://ws.huaien.com/FlashAction.asmx/GetAllListMenu
			 */
			//ws.GetAllListMenu(done);//
			
			/**
			 * ItemID
			 * http://ws.huaien.com/FlashAction.asmx/GetItemList?ItemID=111
			 */
			//ws.GetItemList(GetItemList,110);//获取元素//http://ws.huaien.com/FlashAction.asmx/GetItemList?ItemID=110
		
			
			/**
			 * 单人馆头像，传入馆GuanID
			 * http://ws.huaien.com/FlashAction.asmx/GuanHeadImg?GuanID=1000368
			 */
			//ws.GuanHeadImg(done,1000368);//
			
			
			/**
			 * styleName//获取场馆信息
			 * http://ws.huaien.com/FlashAction.asmx/GetFlashStyleList?InfoPeopleID=1000105
			 */
			//ws.GetFlashStyleList(GetFlashStyleList,1000306);
			/**
			 * 祭拜记录
			 * http://ws.huaien.com/FlashAction.asmx/AddAction?KeyID=1000368&ElementID=115&ElementTitle=%22%BB%A8%C8%A6%22&ElementContent=%22%D6%C1%C7%E9%D6%AE%C3%C0%22&LayoutID=115&ActionID=1&pastDate=2012-12-26T11:42:22.353&ctrolName=%22%22
			 */
			//ws.AddAction(AddAction,1000306/*场馆号*/, 115/*ElementID*/,"花圈"/* ElementTitle*/, "至情之美"/*ElementContent*/, 115/*LayoutID*/, 1/*ActionID*/, /*pastDate*/, "DragDropRenderer94"/*ctrolName*/);//service.AddAction(keyID, ElementID, ElementTitle, ElementContent, LayoutID, ActionID, pastDate, ctrolName);
			//ws.GetListAction(GetListAction,1000306);//获取??http://ws.huaien.com/FlashAction.asmx/GetListAction?KeyID=1000368
			//ws.GetListVAction(GetListVAction,1000306);//获取??http://ws.huaien.com/FlashAction.asmx/GetListVAction?KeyID=1000368
			
			/**
			 * http://ws.huaien.com/FlashAction.asmx/NewestElementOnEveryWhere?keyid=1000368
			 */
			//ws.NewestElementOnEveryWhere(NewestElementOnEveryWhere,1000368);//获取??
			/**
			 * 新建元素
			 * http://ws.huaien.com/FlashAction.asmx/AddElement?typeID=11&name=%22testname%22&path=%22url%22&remark=%22%22&price=1&lastdate=0
			 */
			//ws.AddElement(AddElement,11,"testname","url","0","20","24","0");//获取??//service.AddElement(obj.typeID,obj.name,obj.path,"0","20","24","0");
			//ws.GetListElement(GetListElement, 11);//获取元素
			
			/**
			 * getMenuByType
			 * http://ws.huaien.com/FlashAction.asmx/GetListMenu?FMenuid=//不行？？
			 */
			//ws.GetListMenu(GetListMenu,"火供");//getMenuByType
			/**
			 * 获取音乐
			 */
			//ws.GetMusicList(done);//
			
			
			
			
			
			
			
			
			
			/**
			 * http://ws.huaien.com/FlashAction.asmx/getDropData?Stdmode=default
			 */
			//ws.getDropData(getDropData);//获取??http://ws.huaien.com/FlashAction.asmx/getDropData?Stdmode=
				
			
			
			
			//initTime = getTimer();
			/**
			 * jwid？？？？？？？？？
			 * http://ws.huaien.com/FlashAction.asmx?WSDL/GetjwList
			 * http://ws.huaien.com/FlashAction.asmx/GetjwList?JWTYPEID=
			 */
			//ws.GetjwList(GetjwList, 1000306);//获取??？？？？？？？？？？？？？
			/**
			 * ？？？？？？？？？？？？
			 * http://ws.huaien.com/FlashAction.asmx/YuanHeadImg?YuanID=
			 */
			//ws.YuanHeadImg(done,1000368);//获取园头像
			
			
			
			
			//ws.ResolveIP(done, "192.123.0.200", 0);
			//ws.ResolveIP(done2, "192.123.0.200", 0);
			dispatchEvent(evt);
		}
		
		private function UploadHead(xml:XML):void 
		{
			trace(xml);
		}
		
		
		private function GetListMessage(serviceRespone:XML):void 
		{
			//trace("GetListMessage:\n", serviceRespone, "\n******");
			var xml:XML = XML(serviceRespone);
			var soap:Namespace = xml.namespace("soap");
			var GetUserCodeResponse:QName = new QName("http://tempuri.org/", "GetListMessageResponse");
			var GetUserCodeResult:QName = new QName("http://tempuri.org/", "GetListMessageResult");
			ListAction = xml.soap::Body.descendants(GetUserCodeResponse).descendants(GetUserCodeResult)
			trace("GetListMessage:\n",ListAction);
		}
		
		private function GetjwList(serviceRespone:XML):void 
		{
			//trace("GetjwList:\n", serviceRespone, "\n******");
			var xml:XML = XML(serviceRespone);
			var soap:Namespace = xml.namespace("soap");
			var GetUserCodeResponse:QName = new QName("http://tempuri.org/", "GetjwListResponse");
			var GetUserCodeResult:QName = new QName("http://tempuri.org/", "GetjwListResult");
			ListAction = xml.soap::Body.descendants(GetUserCodeResponse).descendants(GetUserCodeResult)
			//trace("GetjwList:\n",ListAction);
		}
		
		private function GetFlashStyleList(serviceRespone:XML):void 
		{
			//trace("GetFlashStyleList:\n", serviceRespone, "\n******");
			var xml:XML = XML(serviceRespone);
			var soap:Namespace = xml.namespace("soap");
			var GetUserCodeResponse:QName = new QName("http://tempuri.org/", "GetFlashStyleListResponse");
			var GetUserCodeResult:QName = new QName("http://tempuri.org/", "GetFlashStyleListResult");
			ListAction = xml.soap::Body.descendants(GetUserCodeResponse).descendants(GetUserCodeResult)
			//trace("GetFlashStyleList:\n",ListAction);
		}
		
		private function AddFlashMessage(serviceRespone:XML):void 
		{
			//trace("AddFlashMessage:\n", serviceRespone, "\n******");
			var xml:XML = XML(serviceRespone);
			var soap:Namespace = xml.namespace("soap");
			var GetUserCodeResponse:QName = new QName("http://tempuri.org/", "AddFlashMessageResponse");
			var GetUserCodeResult:QName = new QName("http://tempuri.org/", "AddFlashMessageResult");
			ListAction = xml.soap::Body.descendants(GetUserCodeResponse).descendants(GetUserCodeResult)
			//trace("AddFlashMessage:\n",ListAction);
		}
		
		private function getMessageData(serviceRespone:XML):void 
		{
			//trace("GetListVAction:\n", serviceRespone, "\n******");
			var xml:XML = XML(serviceRespone);
			var soap:Namespace = xml.namespace("soap");
			var GetUserCodeResponse:QName = new QName("http://tempuri.org/", "getMessageDataResponse");
			var GetUserCodeResult:QName = new QName("http://tempuri.org/", "getMessageDataResult");
			ListAction = xml.soap::Body.descendants(GetUserCodeResponse).descendants(GetUserCodeResult)
			//trace("getMessageData:\n",ListAction);
		}
		
		private function AddAction(serviceRespone:XML):void 
		{
			//trace("GetListVAction:\n", serviceRespone, "\n******");
			var xml:XML = XML(serviceRespone);
			var soap:Namespace = xml.namespace("soap");
			var GetUserCodeResponse:QName = new QName("http://tempuri.org/", "AddActionResponse");
			var GetUserCodeResult:QName = new QName("http://tempuri.org/", "AddActionWhereResult");
			ListAction = xml.soap::Body.descendants(GetUserCodeResponse).descendants(GetUserCodeResult)
			//trace("AddAction:\n",ListAction);
		}
		
		private function NewestElementOnEveryWhere(serviceRespone:XML):void 
		{
			//trace("GetListVAction:\n", serviceRespone, "\n******");
			var xml:XML = XML(serviceRespone);
			var soap:Namespace = xml.namespace("soap");
			var GetUserCodeResponse:QName = new QName("http://tempuri.org/", "NewestElementOnEveryWhereResponse");
			var GetUserCodeResult:QName = new QName("http://tempuri.org/", "NewestElementOnEveryWhereResult");
			ListAction = xml.soap::Body.descendants(GetUserCodeResponse).descendants(GetUserCodeResult)
			//trace("NewestElementOnEveryWhere:\n",ListAction);
		}
		
		private function GetListVAction(serviceRespone:XML):void 
		{
			//trace("GetListVAction:\n", serviceRespone, "\n******");
			var xml:XML = XML(serviceRespone);
			var soap:Namespace = xml.namespace("soap");
			var GetUserCodeResponse:QName = new QName("http://tempuri.org/", "GetListVActionResponse");
			var GetUserCodeResult:QName = new QName("http://tempuri.org/", "GetListVActionResult");
			ListAction = xml.soap::Body.descendants(GetUserCodeResponse).descendants(GetUserCodeResult)
			//trace("GetListVAction:\n",ListAction);
		}
		
		private function GetListAction(serviceRespone:XML):void 
		{
			//trace("GetListAction:\n", serviceRespone, "\n******");
			var xml:XML = XML(serviceRespone);
			var soap:Namespace = xml.namespace("soap");
			var GetUserCodeResponse:QName = new QName("http://tempuri.org/", "GetListActionResponse");
			var GetUserCodeResult:QName = new QName("http://tempuri.org/", "GetListActionResult");
			ListAction = xml.soap::Body.descendants(GetUserCodeResponse).descendants(GetUserCodeResult)
			//trace("GetListAction:\n",ListAction);
		}
		private function AddElement(serviceRespone:XML):void 
		{
			//trace("AddElement:\n", serviceRespone, "\n******");
			var xml:XML = XML(serviceRespone);
			var soap:Namespace = xml.namespace("soap");
			var GetUserCodeResponse:QName = new QName("http://tempuri.org/", "AddElementResponse");
			var GetUserCodeResult:QName = new QName("http://tempuri.org/", "AddElementResult");
			var result:String = xml.soap::Body.descendants(GetUserCodeResponse).descendants(GetUserCodeResult)
			//trace("AddElement:\n",result);
		}
		
		private function GetListElement(serviceRespone:XML):void 
		{
			//trace("GetListElement:\n", serviceRespone, "\n******");
			var xml:XML = XML(serviceRespone);
			var soap:Namespace = xml.namespace("soap");
			var GetUserCodeResponse:QName = new QName("http://tempuri.org/", "GetListElementResponse");
			var GetUserCodeResult:QName = new QName("http://tempuri.org/", "GetListElementResult");
			ListElement = xml.soap::Body.descendants(GetUserCodeResponse).descendants(GetUserCodeResult)
			//trace("GetListElement:\n",ListElement);
		}
		
		private function getDropData(serviceRespone:XML):void 
		{
			//trace("getDropData:\n", serviceRespone, "\n******");
			var xml:XML = XML(serviceRespone);
			var soap:Namespace = xml.namespace("soap");
			var GetUserCodeResponse:QName = new QName("http://tempuri.org/", "getDropDataResponse");
			var GetUserCodeResult:QName = new QName("http://tempuri.org/", "getDropDataResult");
			var result:String = xml.soap::Body.descendants(GetUserCodeResponse).descendants(GetUserCodeResult)
			//trace("getDropData:\n",result);
		}
		
		private function GetListMenu(serviceRespone:XML):void 
		{
			//trace("GetListMenu:\n", serviceRespone, "\n******");
			var xml:XML = XML(serviceRespone);
			var soap:Namespace = xml.namespace("soap");
			var GetUserCodeResponse:QName = new QName("http://tempuri.org/", "GetListMenuResponse");
			var GetUserCodeResult:QName = new QName("http://tempuri.org/", "GetListMenuResult");
			var result:String  = xml.soap::Body.descendants(GetUserCodeResponse).descendants(GetUserCodeResult)
			//trace("GetListMenu:\n",result);
		}
		private function GetItemList(serviceRespone:XML):void 
		{
			//trace("GetItemList:\n", serviceRespone, "\n******");
			var xml:XML = XML(serviceRespone);
			var soap:Namespace = xml.namespace("soap");
			var GetUserCodeResponse:QName = new QName("http://tempuri.org/", "GetItemListResponse");
			var GetUserCodeResult:QName = new QName("http://tempuri.org/", "GetItemListResult");
			var result:String  = xml.soap::Body.descendants(GetUserCodeResponse).descendants(GetUserCodeResult)
			//trace("GetItemList:\n",result);
		}
		
		private function GetUserName(serviceRespone:XML):void 
		{
			//trace("getUserName:\n", serviceRespone, "\n******");
			var xml:XML = XML(serviceRespone);
			var soap:Namespace = xml.namespace("soap");
			var GetUserCodeResponse:QName = new QName("http://tempuri.org/", "GetUserNameResponse");
			var GetUserCodeResult:QName = new QName("http://tempuri.org/", "GetUserNameResult");
			UserName = String(xml.soap::Body.descendants(GetUserCodeResponse).descendants(GetUserCodeResult));
			
			if (UserName == null || UserName == "null" || UserName == "") UserName = String(UserCode);
			logs.adds("UserName:",UserName);
			//trace("getUserName:\n",UserName);
		}
		
		public function GetUserCode(serviceRespone:XML):void 
		{
			
			//logs.adds("UserCode:\n", serviceRespone, "\n******");
			
			var xml:XML = XML(serviceRespone);
			
			var soap:Namespace = xml.namespace("soap");
			var GetUserCodeResponse:QName = new QName("http://tempuri.org/", "GetUserCodeResponse");
			var GetUserCodeResult:QName = new QName("http://tempuri.org/", "GetUserCodeResult");
			UserCode = uint(xml.soap::Body.descendants(GetUserCodeResponse).descendants(GetUserCodeResult));
			logs.adds("GetUserCode:",UserCode);
			
			ws.GetUserName(GetUserName);
			
		}

		private function done(serviceRespone:XML):void{
			trace("\nWeb Service Result: ");
			var time:Number = getTimer();
			//trace("Call duration: "+(time - initTime)+" milliseconds");
			//initTime = time;
			trace("user code:",serviceRespone);
			
			var xml:XML = XML(serviceRespone);
			
			var ns:Namespace = xml.namespace("soap");
			
			//trace( (xml.ns::Body).GetAllListMenuResponse.toXMLString() ); //显示 dfdf
			//var qnxx:QName = new QName("http://tempuri.org/", "GetAllListMenuResponse");
			//trace(xml.descendants(qnxx));//输出: batdada001;
			//trace(xml.ns::Body.elements("*")[0].elements("*")[0].elements("*")[0].toXMLString());
		}

		private function done2(resp:XML):void{
			trace("\nCached Web Service Result: ");
			var time:Number = getTimer();
			//trace("Call duration: "+(time - initTime)+" milliseconds");
			//initTime = time;
			trace(resp);
			ws.clearCache();
			trace("\nCache was cleared");
			ws.ResolveIP(done, "192.168.0.125", 0);
		}
	}

}